/*
 * @(#)InterceptorInfo.java $version 2010. 8. 11
 *
 * Copyright 2007-2010 NHN Corp. All rights Reserved. 
 * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.nhncorp.usf.core.config;

import java.util.HashMap;
import java.util.Map;

/**
 * 환경 파일로부터의 Interceptor 정보를 넣을 모델.
 *
 * @author Web Platform Development Team
 */
public final class InterceptorInfo {
    /**
     * 현재 객체 참조자.
     */
    private static InterceptorInfo interceptorInfo;

    /**
     * 기본적으로 수행될 InterceptorStack 참조.
     */
    private String defaultInterceptorRef;

    /**
     * Interceptor 정보를 저장하는 {@link Map}
     */
    private Map<String, String> interceptors = new HashMap<String, String>();

    /**
     * InterceptorStack 을 저장하는 {@link Map}
     */
    private Map<String, InterceptorStackInfo> interceptorStacks = new HashMap<String, InterceptorStackInfo>();

    /**
     * 생성자
     */
    private InterceptorInfo() {
    }

    /**
     * InterceptorInfo 객체 반환.
     *
     * @return the InterceptorInfo
     */
    public static InterceptorInfo getInstance() {
        if (interceptorInfo == null) {
            interceptorInfo = new InterceptorInfo();
        }

        return interceptorInfo;
    }

    /**
     * 기본적으로 수행될 InterceptorStack 참조 설정.
     *
     * @param defaultInterceptorStack the default interceptor stack ref name
     */
    public void setDefaultInterceptorRef(String defaultInterceptorStack) {
        this.defaultInterceptorRef = defaultInterceptorStack;
    }

    /**
     * 기본적으로 수행될 InterceptorStack 참조 반환.
     *
     * @return the default interceptor stack ref name
     */
    public String getDefaultInterceptorRef() {
        return this.defaultInterceptorRef;
    }

    /**
     * Interceptor 정보 추가.
     *
     * @param name  the interceptor name
     * @param clazz the interceptor class full name
     */
    public void addInterceptorInfo(String name, String clazz) {
        interceptors.put(name, clazz);
    }

    /**
     * Interceptor 정보(Class) 반환.
     *
     * @param name the interceptor name
     * @return the interceptor class full name
     */
    public String getInterceptorClass(String name) {
        return interceptors.get(name);
    }

    /**
     * Returns <tt>true</tt> if this map contains a mapping for the specified
     * interceptor of name.
     *
     * @param name the interceptor name
     * @return the interceptor exist or don't exist
     */
    public boolean containsInterceptor(String name) {
        return interceptors.containsKey(name);
    }

    /**
     * {@link InterceptorStackInfo} 추가.
     *
     * @param name                 the interceptor name
     * @param interceptorStackInfo the InterceptorInfo
     */
    public void addInterceptorStackInfo(String name, InterceptorStackInfo interceptorStackInfo) {
        interceptorStacks.put(name, interceptorStackInfo);
    }

    /**
     * {@link InterceptorStackInfo} 반환.
     *
     * @param name the interceptor name
     * @return the InterceptorStackInfo
     */
    public InterceptorStackInfo getInterceptorStackInfo(String name) {
        return interceptorStacks.get(name);
    }

    /**
     * Returns <tt>true</tt> if this map contains a mapping for the specified
     * InterceptorStack of name.
     *
     * @param name the intereptor stack name
     * @return the interceptor stack exist or don't exist
     */
    public boolean containsInterceptorStackInfo(String name) {
        return interceptorStacks.containsKey(name);
    }

    /**
     * 모든 정보 삭제.
     */
    public void clean() {
        setDefaultInterceptorRef(null);
        interceptors.clear();
        interceptorStacks.clear();
    }
}
